namespace DotNetNuke.Data
{
    using System;
    using System.Data;
    using System.Runtime.InteropServices;

    [AttributeUsage(AttributeTargets.Parameter)]
    public class SqlParameterAttribute : Attribute
    {
        private ParameterDirection _direction;
        private bool _directionDefined;
        private string _name;
        private System.Data.SqlDbType _paramType;
        private bool _paramTypeDefined;
        private byte _precision;
        private byte _scale;
        private int _size;
        //TO DefaultParameterVale of System.Data.SqlDbType, what's that?
        public SqlParameterAttribute([Optional, DefaultParameterValue(null)] string name, [Optional, DefaultParameterValue(SqlDbType.BigInt)] System.Data.SqlDbType paramType, [Optional, DefaultParameterValue(0)] int size, [Optional, DefaultParameterValue((byte)0)] byte precision, [Optional, DefaultParameterValue((byte)0)] byte scale, [Optional, DefaultParameterValue((ParameterDirection)(0))] ParameterDirection direction)
        {
            this._name = name;
            this._paramType = paramType;
            if (paramType == System.Data.SqlDbType.BigInt)
            {
                this._paramTypeDefined = false;
            }
            else
            {
                this._paramTypeDefined = true;
            }
            this._size = size;
            this._precision = precision;
            this._scale = scale;
            this._direction = direction;
            if (direction == ((ParameterDirection) 0))
            {
                this._directionDefined = false;
            }
            else
            {
                this._directionDefined = true;
            }
        }

        public ParameterDirection Direction
        {
            get
            {
                return this._direction;
            }
            set
            {
                this._direction = value;
            }
        }

        public bool IsDirectionDefined
        {
            get
            {
                return this._directionDefined;
            }
        }

        public bool IsNameDefined
        {
            get
            {
                bool IsNameDefined = true;
                if (this._name == null)
                {
                    return false;
                }
                if (this._name.Length == 0)
                {
                    IsNameDefined = false;
                }
                return IsNameDefined;
            }
        }

        public bool IsPrecisionDefined
        {
            get
            {
                return (this._precision != 0);
            }
        }

        public bool IsScaleDefined
        {
            get
            {
                return (this._scale != 0);
            }
        }

        public bool IsSizeDefined
        {
            get
            {
                return (this._size != 0);
            }
        }

        public bool IsTypeDefined
        {
            get
            {
                return this._paramTypeDefined;
            }
        }

        public string Name
        {
            get
            {
                if (this._name == null)
                {
                    return string.Empty;
                }
                return this._name;
            }
            set
            {
                this._name = value;
            }
        }

        public byte Precision
        {
            get
            {
                return this._precision;
            }
            set
            {
                this._precision = value;
            }
        }

        public byte Scale
        {
            get
            {
                return this._scale;
            }
            set
            {
                this._scale = value;
            }
        }

        public int Size
        {
            get
            {
                return this._size;
            }
            set
            {
                this._size = value;
            }
        }

        public System.Data.SqlDbType SqlDbType
        {
            get
            {
                return this._paramType;
            }
            set
            {
                this._paramType = value;
            }
        }
    }
}

